#  Copyright (c) 2020 - ~, WANGXI
#  
#  DELAY VARIANCE ANALYSYS AWK FILE
#  Used in NS-2 simulator
#  Clone from https://gitee.com/WangXi_Chn/ns2_modulelib
#  Note in https://www.yuque.com/wangxi_chn/kozrfl
#  
#  Change Logs:
#  Date           Author       Notes			Mail
#  2020-12-09     WangXi   	   first version	WangXi_Chn@foxmail.com

BEGIN {
    # 程序初始化
    old_time = 0;
    old_seq_no = 0;
    i = 0;

}

{
    action = $1; 
    time = $2;
    node_1 = $3;
    node_2 = $4;
    type = $5;
    pktsize = $6;
    flow_id = $8;
    node_1_address = $9;
    node_2_address = $10;
    seq_no = $11;
    packet_id = $12;

    if(node_1 == 2 && node_2 == 3 && type == "cbr" && action == "r"){
        # 求出目前包的序号和上次成功接收的序号差值
        dif = seq_no - old_seq_no;

        # 处理第一个接收包
        if(dif == 0){
            dif = 1;
        }

        # 求出jitter
        jitter[i] = (time-old_time)/dif;
        seq[i] = seq_no;
        i = i+1;
        old_seq_no = seq_no;
        old_time = time;
    }
}

END {
    for(j=1;j<i;j++){
        printf("%d\t%f\n",seq[j],jitter[j])
    }
}

#/ ************************ (C) COPYRIGHT 2020 WANGXI **************END OF FILE****/
